package com.api.oa.controller;

import com.api.oa.model.entity.OaOfficeNav;
import com.api.oa.services.IOaOfficeNavService;
import com.api.shopapi.controller.BaseController;
import com.api.shopapi.entity.MyResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/oa/org/office")
public class OaOfficeNavController extends BaseController {


    @Autowired
    private IOaOfficeNavService iOaOfficeNavService;

    @RequestMapping(value = "/add", method = RequestMethod.POST)
    public MyResult Add(@RequestBody OaOfficeNav org) {
        try {
            return iOaOfficeNavService.add(org) == 1 ? success(org) : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/remove/{id}", method = RequestMethod.GET)
    public MyResult remove(@PathVariable Long id) {
        try {
            iOaOfficeNavService.remove(id);
            return success("删除成功!");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/update", method = RequestMethod.POST)
    public MyResult update(@RequestBody OaOfficeNav org) {
        try {
            return iOaOfficeNavService.update(org) == 1 ? success("修改成功!") : failed("操作失败");
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }

    }


    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public MyResult list(@RequestParam(defaultValue = "") String key,@RequestParam(defaultValue = "1") Integer pageIndex,@RequestParam(defaultValue = "10") Integer pageSize) {
        try {
            return success(iOaOfficeNavService.list(key,pageIndex,pageSize));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }


    @RequestMapping(value = "/one/{id}", method = RequestMethod.GET)
    public MyResult one(@PathVariable Long id) {
        try {
            return success(id == null ? null : iOaOfficeNavService.one(id));
        } catch (Exception e) {
            return anomalous(getExceptionMsg(e));
        }
    }

}
